'use strict';

/**
 * @ngdoc directive
 * @name webApp.directive:swipe
 * @description
 * # swipe
 */
angular.module('webApp')
  .directive('swipeTouch', function ($swipe,browser) {
    return {
      restrict: 'AE',
      replace: false,
      link: function postLink(scope, element, attrs) {
        //手势
        var startX,startY,endX,endY;
        $swipe.bind(element,{
          'start': function(coords){
            startX = coords.x;
            startY = coords.y;
          },
          'end': function(coords) {
            endX = coords.x;
            endY = coords.y;
            if (Math.pow(Math.pow((startX - endX), 2) + Math.pow((startY - endY), 2), 1 / 2) >= browser.factory()[0] / 2) {
              if (endX - startX > 0) {
                //回退
                history.go(-1);
              }
              else{
                //前进
                history.go(+1);
              }
            }
          }
        });
      }
    };
  });
